#include <iostream>
#include <vector>
#include <utility>

int n, p;

int main()
{
	int T; std::cin >> T;
	while (T--) {
		std::cin >> n >> p;
		std::vector<std::pair<int, int>> ans;
		for (int i = 0; i < n; i++) {
			ans.push_back({i, (i + 1) % n});
			ans.push_back({i, (i + 2) % n});
		}
		int t = 3;
		for (int i = 0; p; p--) {
			ans.push_back({i % n, (i + t) % n});
			if (++i >= n) i = 0, t++;
		}
		for (auto i : ans)
			std::cout << i.first + 1 << ' ' << i.second + 1 << '\n';
	}
}

